
<?php
 session_start(); 
 include("admin/include/db.php");
 include("admin/include/common.php");
 
 if(isset($_REQUEST) && $_REQUEST['action'] == 'submit'){
	
	$randomNumber = rand(10000,20000).'_'.time();
	$cartProducts = explode(',',$_SESSION['cart']);
	$cartProducts = array_unique($cartProducts); 

	if(!empty($cartProducts)){
		foreach($cartProducts as $prod ){
			if($prod > 0)
			{
				 $sqlQuery = "INSERT INTO prool_order_product(product_name,order_id)VALUES
							('".$prod."',
							 '".$randomNumber."')";
				mysql_query($sqlQuery);
			 }	
		 } 
		
		 $sqlOrder = mysql_query("INSERT INTO `prool_order` 
								 SET
								 	time_id			=   '".time()."',
									s_firt_name		=	'".$_REQUEST['s_firt_name']."',
									s_last_name		=	'".$_REQUEST['s_last_name']."',
									s_address1		=	'".$_REQUEST['s_address1']."',
									s_address2		=	'".$_REQUEST['s_address2']."',
									s_phone_number	=	'".$_REQUEST['s_phone_number']."',
									s_mobile_number	=	'".$_REQUEST['s_mobile_number']."',
									s_province		=	'".$_REQUEST['s_province']."',
									s_city			=	'".$_REQUEST['s_city']."',
									s_country		=	'".$_REQUEST['s_country']."',
									p_firt_name		=	'".$_REQUEST['p_firt_name']."',
									p_last_name		=	'".$_REQUEST['p_last_name']."',
									p_address1		=	'".$_REQUEST['p_address1']."',
									p_address2		=	'".$_REQUEST['p_address2']."',
									p_phone_number	=	'".$_REQUEST['p_phone_number']."',
									p_mobile_number	=	'".$_REQUEST['p_mobile_number']."',
									p_province		=	'".$_REQUEST['p_province']."',
									p_city			=	'".$_REQUEST['p_city']."',
									p_country		=	'".$_REQUEST['p_country']."',
									random_order_id	=	'".$randomNumber."',
									amount			=	'".totalAmount()."'");
	
		unset($_SESSION['cart']);
	}
	
	header("location:successful_order.php");
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$resPages['page_title']?></title>
</head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<center>
<script >
function validation(){
	var message  = '';
	var first_name = document.getElementById("s_firt_name").value;
	var last_name  = document.getElementById("s_last_name").value;
	var address = document.getElementById("s_address1").value;
	var mobile 	= document.getElementById("s_mobile_number").value;
	var phone 	= document.getElementById("s_phone_number").value;
	var city 	= document.getElementById("s_city").value;
	var state 	= document.getElementById("s_province").value;
	var country = document.getElementById("s_country").value;

	if(first_name == ''){
		message += 'Please enter your first name. \n';
	}
	if(last_name == ''){
		message += 'Please enter your last name. \n';
	}
	
	if(address == ''){
		message += 'Please enter your address. \n';
	}
	if(mobile == ''){
		message += 'Please enter your mobile number. \n';
	}
	if(phone == ''){
		message += 'Please enter phone number. \n';
	}
	if(city == ''){
		message += 'Please enter your city. \n';
	}
	if(state == ''){
		message += 'Please enter your state. \n';
	}
	if(country == ''){
		message += 'Please enter your country. \n';
	}
	
	if(message != ''){
		alert(message);
		return false;	
	}
	
}

function setInformation(){

	var message 		= '';
	var setinfo 		= document.form1.chk_same;
	var s_firt_name 	= document.getElementById("s_firt_name").value;
	var s_last_name 	= document.getElementById("s_last_name").value;
	var s_address1 		= document.getElementById("s_address1").value;
	var s_address2 		= document.getElementById("s_address2").value;
	var s_phone_number  = document.getElementById("s_phone_number").value;
	var s_mobile_number = document.getElementById("s_mobile_number").value;
	var s_province	 	= document.getElementById("s_province").value;
	var s_city 			= document.getElementById("s_city").value;
	var s_country 		= document.getElementById("s_country").value;
	 
	if(s_firt_name == ''){
		message += 'Please enter first name\n';
	}
	if(s_last_name == ''){
		message += 'Please enter last name\n';
	
	}
	if(s_address1 == ''){
		message += 'Please enter your address\n';
	
	}
	if(s_address2 == ''){
		message += 'Please enter your address\n';
	
	}
	if(s_phone_number == ''){
		message += 'Please enter your phone number\n';
	
	}
	if(s_mobile_number == ''){
		message += 'Please enter your mobile number\n';
	}
	if(s_province == ''){
		message += 'Please enter your province\n';
	}
	if(s_city == ''){
		message += 'Please enter your city\n';
	}
	if(s_country == ''){
		message += 'Please enter your country\n';
	}

	if(setinfo.checked == true){
			document.getElementById("p_firt_name").value	=	s_firt_name;
			document.getElementById("p_last_name").value	=	s_last_name;
			document.getElementById("p_address1").value		=	s_address1;
			document.getElementById("p_address2").value		=	s_address2;
			document.getElementById("p_phone_number").value	=	s_phone_number;
			document.getElementById("p_mobile_number").value=	s_mobile_number;
			document.getElementById("p_province").value		=	s_province;
			document.getElementById("p_city").value			=	s_city;
			document.getElementById("p_country").value		=	s_country;
	}else{
			document.getElementById("p_firt_name").value	=	'';
			document.getElementById("p_last_name").value	=	'';
			document.getElementById("p_address1").value		=	'';
			document.getElementById("p_address2").value		=	'';
			document.getElementById("p_phone_number").value	=	'';
			document.getElementById("p_mobile_number").value=	'';
			document.getElementById("p_province").value		=	'';
			document.getElementById("p_city").value			=	'';
			document.getElementById("p_country").value		=	'';
	}
	
	if(message != ''){
		return false;
	}
	
}

</script>
<body align="center"  >
<form id="form1" name="form1" onsubmit="return validation();" >
<input type="hidden" id="action" name="action" value="submit"  />
<div class="main_bg" style="height:728px"   >
	<div align="center" >
 		<div class="main_bg_earth" align="center" >
    		<div  style="width:793px;" align="center" >
				<div class="main_bg_logo" style="padding-top:162px" >
				 	<div class="main_bg_repeat_img"  >
					<?php
								include("includes/header.php");
							?>
							<div style="margin-bottom:5px" >&nbsp;</div>
						<div style="margin-left:100px" >
							
        	<div style=" width:600px; padding-left:3px; float:left;padding-bottom:10px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#333333"   >
       		<div class="heading" style="margin-bottom:30px; font-family:Arial, Helvetica, sans-serif" >
            	Your Shipping Information
            </div>
            <div >
            <div style=" width:700px; height:25px; padding-top:8px;;" class="divGrid" > 
                <div style="float:left; padding-top:10px; margin-bottom:5px; width:600px; height:25px; color:#FFFFFF; background-color:#0D6BE0;padding-left:10px" align="left">Shipping Information</div>

                <div style=" clear:both" ></div>
              </div>
            <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left"  >First Name:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_firt_name" name="s_firt_name" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
            <div id="login" >
            	<div style=" width:600px; margin-top:10px" >
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Last Name:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_last_name" name="s_last_name" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>         
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Address1:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_address1" name="s_address1" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" >  
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Address2:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_address2" name="s_address2" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Phone Number:</div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_phone_number" name="s_phone_number" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" >
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Mobile Number:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_mobile_number" name="s_mobile_number" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Provice:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_province" name="s_province" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" >
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >City:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_city" name="s_city" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Country:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="s_country" name="s_country" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
           </div>
            <div >
            <div style=" width:700px; height:25px; padding-top:8px; margin-top:20px" class="divGrid" > 
                <div style="float:left; padding-top:10px; margin-bottom:5px; width:600px; height:25px; color:#FFFFFF; background-color:#0D6BE0;padding-left:10px" align="left">Your Payment Information <input type="checkbox" id="chk_same" name="chk_same" onclick="return setInformation();" value="1"  />Same as shipping information</div>
 
                <div style=" clear:both" ></div>
              </div>
            <div id="login" >
            	<div style=" width:600px; margin-top:10px" >         
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >First Name:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_firt_name" name="p_firt_name" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
            <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Last Name:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_last_name" name="p_last_name" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Address1:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_address1" name="p_address1" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Address2:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_address2" name="p_address2" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Phone Number:</div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_phone_number" name="p_phone_number" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" >
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Mobile Number:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_mobile_number" name="p_mobile_number" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Provice:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_province" name="p_province" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >City:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_city" name="p_city" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
             <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div style="float:left; width:200px; padding-left:30px" align="left" class="label" >Country:<span class="clsValidation" >*</span></div>
                    <div style="float:left; width:200px; padding-left:30px" align="left" ><input type="text" id="p_country" name="p_country" class="textbox_login"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
            </div>
           </div>
            <div id="login" >
            	<div style=" width:600px; margin-top:10px" > 
                	<div ><input type="submit" value="Proceed to Next Step" class="buttons"  /></div> 
                </div>
            </div>
         </div>
		 <div style="clear:both" ></div>
 
						</div>
							<?php
								include("includes/footer_menu.php");
							?>
						 </div>
						 
						 <?php include("includes/footer.php");?>
						</div>
           		 </div>
    		</div>
       </div>
</div>
</div>
</form>
</body>
</center>
</html>
